#coding=utf-8
'''
Created on 2017-04-20

@author: sandy
'''

import json
from pycommon import Pack as packet
from pycommon import Const,Utils
from pycommon import RemoteManager
import ServerConfig

def loginCenter(reloginCount):
    return packet.pack("HHsHB",Const.CMD_GAME2CT_LOGIN,RemoteManager.instance.sid,Utils.u2pstr(ServerConfig.instance.public_ip),ServerConfig.instance.public_port,reloginCount)

def hallInfo(l):
    return packet.pack("HS",Const.CMD_GAME2CT_HALL_INFO,json.dumps(l))

def reportHallOnline(result):
    lc = len(result.keys())
    ret = packet.pack("HH",Const.CMD_GAME2CT_REPORT_HALL,lc)
    for hid in result:
        s = packet.pack("HH",hid,result.get(hid))
        ret += s
    return ret

def createTable(code,queneId,hallId,tableId):
    return packet.pack("HHHHH",Const.CMD_GAME2CT_CREATE_TABLE,code,queneId,hallId,tableId)

def enterTable(tableIdStr,uid):
    return packet.pack("HsI",Const.CMD_GAME2CT_ENTER_TABLE,Utils.u2pstr(tableIdStr),uid)

def checkUser(uid,session,cid):
    return packet.pack("HIsH",Const.CMD_GAME2CT_CHECK_USER,uid,session,cid)

def userLogin(uid,hallid):
    return packet.pack("HIH",Const.CMD_GAME2CT_USER_LOGIN,uid,hallid)
    pass

def userLogout(uid,reason=0,drop=0):
    return packet.pack("HIBB",Const.CMD_GAME2CT_USER_LOGOUT,uid,reason,drop)
    pass

def enterHallErr(hallid,code):
    pass

